package com.vae.mall.common.exception.handle;


import com.vae.mall.common.response.RespResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;

/**
 * 全局异常处理
 */
@ControllerAdvice
public class GlobalExceptionHandle {

    @ExceptionHandler(Exception.class)
    public RespResult<String> handleAllExceptions(Exception ex, WebRequest request) {
        // 这里可以记录日志、返回错误信息等
        return RespResult.error(ex.getMessage());
    }

    @ExceptionHandler(NullPointerException.class)
    public RespResult<String> handleNullPointerExceptions(NullPointerException ex, WebRequest request) {
        // 特殊处理NullPointerException
        return RespResult.error(ex.getMessage());
    }

}
